package org.example.web;

import org.example.bean.StudentInfo;
import org.example.dto.StudentInfoDTO;
import org.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;
    @PostMapping("/api/inst")
    public StudentInfoDTO tianjia(@RequestBody StudentInfoDTO studentInfoDTo){
        // 1. 将 DTO 转换为实体类
        StudentInfo studentInfo = new StudentInfo();
        studentInfo.setExamNumber(studentInfoDTo.getExamNumber());
        studentInfo.setLasName(studentInfoDTo.getLasName());

        // 2. 调用服务层保存数据
        StudentInfo savedStudent = studentService.addStudentInfo(studentInfo);

        // 3. 将保存后的实体类转换回 DTO
        StudentInfoDTO resultDto = new StudentInfoDTO();
        resultDto.setExamNumber(savedStudent.getExamNumber());
        resultDto.setLasName(savedStudent.getLasName());
        // 4. 返回 DTO 对象
        return resultDto;
    }

}
